#include <cstdio>

using namespace std;

const int maxn=3000000, maxt=3000000;

int read() {
    int ret=0;
    char c;
    for (c=getchar(); c<'0' || c>'9'; c=getchar());
    for (; c>='0' && c<='9'; c=getchar()) ret=ret*10+c-'0';
    return ret;
}

int que[2*maxt+1], sum, size, hq=maxt, tq=maxt, zero[2*maxt+1], hz=maxt, tz=maxt;

void pushb(int x) {
    if (!x) zero[tz++] = tq;
    que[tq++] = x;
    sum += x;
    size++;
}

void popb() {
    if (!que[--tq]) zero[--tz]=0;
    sum -= que[tq];
    que[tq] = 0;
    size--;
}

void pushf(int x) {
    que[--hq] = x;
    if (!x) zero[--hz] = hq;
    sum += x;
    size++;
}

void popf() {
    if (!que[hq]) zero[hz++] = 0;
    sum -= que[hq];
    que[hq++] = 0;
    size--;
}

int main() {
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout);

    static int a[maxn+1], ans[maxn+1];
    int n=read(), time=read();
    for (int i=1; i<=n; i++) {
        if (read()) a[++a[0]] = i;
    }

    for (int i=1; i<a[1]; i++) pushb(1);
    for (int i=a[1]; i<=time; i++) pushb(0);
    ans[1] = a[1]-sum;

    for (int i=2; i<=a[0]; i++) {
        popb(), pushf(0);
        for (int j=a[i-1]+1; j<a[i] && hz<tz; j++) {
            sum++;
            que[zero[hz++]] = 1;
        }
        if (size!=time) printf("Err!\n");
        ans[i] = a[i]-sum;
    }

    for (int i=1, p=1; i<=n; i++) {
        if (i==ans[p]) {
            p++;
            printf("1 ");
        } else printf("0 ");
    }
    printf("\n");

    fclose(stdin);
    fclose(stdout);
    return 0;
}
